import requests
import json
import execjs
import time


headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
}
cookies = {
    "sessionid": "q9ha7ar9sr7rdx04wbb518m3gf4dcx6n"
}
url = "https://www.mashangpa.com/api/problem-detail/5/data/"
with open(r'E:\Python\vscode\Crawlers\tuling\第五题屠龙刀\jsdecode_a.js', 'r', encoding='utf-8') as f:
    js = execjs.compile(f.read())
result = 0
for i in range(1,21):
    data = {
        "xl": js.call('loadPage', i)
    }
    data = json.dumps(data, separators=(',', ':'))
    response = requests.post(url, headers=headers, cookies=cookies, data=data)
    current_array = [j for j in response.json()['current_array']]
    result += sum(current_array)
    time.sleep(0.5)
print(result)